package com.wyc.service;

import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Component;

import java.util.concurrent.*;

/**
 * @author
 */
@Component
public class MonitorConsumer {

    @Reference
    private MonitorService monitorService;

    private ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(8,8,100, TimeUnit.MILLISECONDS,new ArrayBlockingQueue<>(1000));

    public void consumer(){
        Runnable runnableA = new Thread(() -> monitorService.methodA());
        Runnable runnableB = new Thread(() -> monitorService.methodB());
        Runnable runnableC = new Thread(() -> monitorService.methodC());
        while (true){
            try{
                threadPoolExecutor.execute(runnableA);
                threadPoolExecutor.execute(runnableB);
                threadPoolExecutor.execute(runnableC);
            } catch (RejectedExecutionException e){
                try {
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException ex) {
                    System.out.println("Thread sleep exception!");
                }
            }

        }
    }
}
